/* 
    1.该文件用于创建一个为count组件服务的reducers,reducers的本质就是一个函数.
    2.reducers函数会接到两个参数,分别为:之前的状态(preState)，动作对象(action)
*/
import { INCREMENT, DECREMENT } from '../counstant'
const initState = 0 //初始化状态
export default function countReducers(preState = initState, action) {
    //从action对象中获取type、data
    let { type, data } = action
    //根据type如何加工数据
    switch (type) {
        //如果是加
        case INCREMENT:
            return preState + data*1
        //如果是减
        case DECREMENT:
            return preState - data*1
        default:
            return preState
    }
}